package com.example.demo2.core.redis;

import com.alibaba.fastjson.JSONObject;
import com.example.demo2.cfg.RedisTemplate;
import com.example.demo2.constant.RedisConstants;
import com.example.demo2.model.User;
import com.example.demo2.service.RedisService;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
public class RedisCacheService {
    @Resource
    private RedisService redisService;


    /**
     * 更新客户个人信息 通过员工Id
     *
     * @param uid
     * @author Sonya Shang
     */
    public void cacheCompanyUser(Integer uid, User user) {
        RedisTemplate.REDIS_DB_INDEX.set(RedisConstants.INDEXDB_0);
        JSONObject jb = new JSONObject();
        jb.put("type", "companyUser");
        jb.put("uid", uid);
        if (redisService.get(RedisConstants.QUARTZ_BASE + uid) == null) {

            redisService.set(RedisConstants.REDIS_COMPANY_USER + uid, jb.toJSONString());
        } else {
            redisService.delUser(RedisConstants.REDIS_COMPANY_USER + uid);
            redisService.set(RedisConstants.REDIS_COMPANY_USER + uid, jb.toJSONString());
        }
    }
}
